package com.whfc.ms.api.fim.controller;

import com.whfc.common.result.ListData;
import com.whfc.common.result.PageData;
import com.whfc.common.result.Result;
import com.whfc.common.result.ResultUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.fim.dto.FimPersonDTO;
import com.whfc.fim.dto.FimPersonImgDTO;
import com.whfc.fim.param.FimImportPersonParam;
import com.whfc.fim.param.FimPersonParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.ms.api.fim.service.MsFimPersonService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Description: 智能监控系统人员管理
 * @author: qzexing
 * @version: 1.0
 * @date: 2020/3/16 17:11
 */
@Deprecated
@RestController
@RequestMapping("/ms/api/fim/person")
public class AppFimPersonController {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private MsFimPersonService msFimPersonService;

    @GetMapping("/list")
    public Result list(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestParam("pageNum") Integer pageNum,
                       @RequestParam("pageSize") Integer pageSize,
                       @RequestParam("deptId") Integer deptId,
                       @RequestParam(value = "keyword", required = false) String keyword) {
        logger.info("人员管理-获取人员列表，loginer:{},pageNum:{},pageSize:{},deptId:{},keyword:{}",
                user.getUsername(), pageNum, pageSize, deptId, keyword);
        PageData<FimPersonDTO> pageData = msFimPersonService.list(pageNum, pageSize, deptId, keyword);
        return ResultUtil.success(pageData);
    }

    @PostMapping("/add")
    public Result add(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @RequestBody @Validated FimPersonParam request) {
        logger.info("人员管理-添加人员，loginer:{},PersonQO:{}", user.getUsername(), request.toString());
        msFimPersonService.add(request);
        return ResultUtil.success();
    }

    @PostMapping("/edit")
    public Result edit(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                       @RequestBody @Validated FimPersonParam request) {
        logger.info("人员管理-修改人员，loginer:{},PersonQO:{}", user.getUsername(), request.toString());
        msFimPersonService.edit(request);
        return ResultUtil.success();
    }

    @PostMapping("/del/{personId}")
    public Result del(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                      @PathVariable("personId") Integer personId) {
        logger.info("人员管理-删除人员,loginer:{},personId:{}", user.getUsername(), personId);
        msFimPersonService.del(personId);
        return ResultUtil.success();
    }


    @PostMapping("/uploadImg")
    public Result uploadImg(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                            @RequestParam(value = "files") MultipartFile[] files) {
        logger.info("人员管理-上传图片,loginer:{}", user.getUsername());
        List<FimPersonImgDTO> list = msFimPersonService.uploadImg(files);
        ListData<FimPersonImgDTO> listData = new ListData<>(list);
        return ResultUtil.success(listData);
    }

    @PostMapping("/import")
    public Result importEmp(@SessionAttribute(SessionAttr.MS_USER) SysUser user,
                            @RequestBody @Validated FimImportPersonParam importPersonParam) {
        logger.info("人员管理-导入劳务人员，loginer:{},importPersonParam:{}", user.getUsername(), importPersonParam);
        msFimPersonService.importEmp(importPersonParam);
        return ResultUtil.success();
    }

}
